home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Demo / tkinter / www / www5.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  512 b   |  30 lines

  1. #! /usr/bin/env python
  2.  
  3. # www5.py -- display the contents of a URL in a Text widget
  4. # - set window title
  5.  
  6. import sys
  7. import urllib
  8. from Tkinter import *
  9.  
  10. def main():
  11.     if len(sys.argv) != 2 or sys.argv[1][:1] == '-':
  12.         print "Usage:", sys.argv[0], "url"
  13.         sys.exit(2)
  14.     url = sys.argv[1]
  15.     fp = urllib.urlopen(url)
  16.  
  17.     root = Tk()
  18.     root.title(url)            # Set window manager title
  19.     text = Text(root)
  20.     text.pack()
  21.  
  22.     while 1:
  23.         line = fp.readline()
  24.         if not line: break
  25.         text.insert('end', line)
  26.  
  27.     text.mainloop()
  28.  
  29. main()
  30.